package com.huilian.iotbox.admin.service.impl;

import com.huilian.iotbox.admin.dao.DisplayRackItemDao;
import com.huilian.iotbox.admin.service.DeviceService;
import com.huilian.iotbox.admin.service.DisplayRackItemService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.DeviceDto;
import com.huilian.iotbox.data.dto.DisplayRackItemDto;
import com.huilian.iotbox.data.vo.DeviceVo;
import com.huilian.iotbox.data.vo.DisplayRackItemVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DisplayRackItemServiceImpl implements DisplayRackItemService {

    @Resource
    private DisplayRackItemDao displayRackItemDao;
    @Resource
    private DeviceService deviceService;

    @Override
    public ServerResponse updateDeviceTypeId(DisplayRackItemDto displayRackItemDto) {
        DeviceDto deviceDto= new DeviceDto();
        deviceDto.setId(displayRackItemDto.getDeviceId());
        deviceDto.setUserInfo(displayRackItemDto.getUserInfo());
        DeviceVo deviceVo = deviceService.findOneDeviceById(deviceDto);
        if(deviceVo==null){
            throw new RuntimeException("设备不存在");
        }
        if(displayRackItemDto.getDisplayRackItemId().size()<1){
            throw new RuntimeException("请选择货道");
        }
        displayRackItemDao.updateDeviceTypeId(displayRackItemDto);
        return ServerResponse.createBySuccess();
    }

    @Override
    public List<DisplayRackItemVo> findDisplayByDeviceIdAndDisplayRackId(DisplayRackItemDto displayRackItemDto) {
        return displayRackItemDao.findDisplayByDeviceIdAndDisplayRackId(displayRackItemDto);
    }

    @Override
    public List<DisplayRackItemVo> findDisplayRackItemByDeviceId(DisplayRackItemDto displayRackItemDto) {
        return displayRackItemDao.findDisplayRackItemByDeviceId(displayRackItemDto);
    }

}
